#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

#define FOR(i,a,n) for(int i=a;i<n;++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

class SuffixArray
{
public:
    int *sa,*rank;
    int *height;
    int keyTypeMax,length;
    SuffixArray(int *a,int n,int m)
    {
        keyTypeMax = max(m,n)+5;
        sa = new int[n+10];
        rank = new int[keyTypeMax];
        height = new int[n+10];
        length = n+1;
        a[n] = 0;
        setSa(a);
        setHeight(a);
    }
    ~SuffixArray()
    {
        delete(sa);
        delete(rank);
        delete(height);
    }
    void setSa(int *a)
    {
        int *cnt = new int[keyTypeMax];
        REP(i,keyTypeMax) cnt[i] = 0;
        REP(i,length) cnt[rank[i] = a[i]]++;
        REP(i,keyTypeMax-1) cnt[i+1] += cnt[i];
        for(int i= length-1; i >= 0; i--) sa[--cnt[rank[i]]] = i;

        int *rankSt = new int[keyTypeMax];
        int *rankStPos = new int[length+10];
        for(int p=0,h=1,rankMax=keyTypeMax;
                p<length;h<<= 1,rankMax=p)
        {
            p = 0;
            FOR(i,length-h,length) rankStPos[p++] = i;
            REP(i,length) if(sa[i]>=h) rankStPos[p++] = sa[i] - h;
            REP(i,length) rankSt[i] = rank[rankStPos[i]];
            REP(i,rankMax) cnt[i] = 0;
            REP(i,length) cnt[rankSt[i]]++;
            REP(i,rankMax-1) cnt[i+1] += cnt[i];
            for(int i=length-1;i>=0;i--) sa[--cnt[rankSt[i]]] = rankStPos[i];

            swap(rank,rankStPos);
            rank[sa[0]] = 0;
            p = 1;
            FOR(i,1,length)
            {
                if(rankStPos[sa[i]] == rankStPos[sa[i-1]]
                   &&rankStPos[sa[i]+h] == rankStPos[sa[i-1]+h])
                    rank[sa[i]] = p-1;
                else rank[sa[i]] = p++;
            }
        }
        delete(rankStPos);
        delete(rankSt);
        delete(cnt);
    }
    void setHeight(int *a)
    {
        int h = 0;
        REP(i,length)
        {
            int r = rank[i];
            if(!r) height[r] = h = 0;
            else
            {
                int pb = sa[r-1];
                int off;
                for(off = (h?h-1:0);a[i+off]==a[pb+off];off++) ;
                height[r] = h = off;;
            }
        }
    }
    bool check(int len)
    {
        if(!len) return true;
        int tmax = -1;
        int tmin = length;
        REP(i,length)
        {
            if(height[i]<len) tmax = sa[i],tmin = sa[i];
            else
            {
                tmax = max(tmax,sa[i]);
                tmin = min(tmin,sa[i]);
                if(tmax - tmin>len) return true;
            }
        }
        return false;
    }
    int getAns()
    {
        int low = 0,high = length-1;
        while(low<=high)
        {
            int mid = (low+high+1)>>1;
            if(check(mid)) low = mid+1;
            else high = mid-1;
        }
        return high+1;
    }
};
int arr[20020],at[20020];
int main()
{
    int length;
    while(cin>>length)
    {
        if(!length) break;
        REP(i,length) scanf("%d",arr+i);
        REP(i,length-1) at[i] = arr[i+1]-arr[i]+90;
        SuffixArray sa(at,length-1,90*2);
        int ans = sa.getAns();
        cout<<(ans>=5?ans:0)<<endl;
    }
    return 0;
}
